import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {HttpClient} from '@angular/common/http';
import {OwnerUploadImgPage} from '../owner-upload-img/owner-upload-img';

declare  var $:any;

/**
 * Generated class for the FacePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-face',
  templateUrl: 'face.html',
})
export class FacePage {
  houseId;
  shenfen:any;
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private http:HttpClient,

  ) {
  }

  ionViewDidLoad() {
    let that = this;
    that.houseId=this.navParams.get('houseId');
  }
  checkCard(fileList: FileList) {
    let that=this;
    if (fileList.length > 0) {


      let file: File = fileList[0];
      // that.sfzpreview(file);
      let formData: FormData = new FormData();
      formData.append('image_file', file, file.name);
      formData.append('api_key', 'dOd42wxHQ7RF-PhISyM-kRdeMZr1HsaR');
      formData.append('api_secret', 'T0dp9buMNetuUcjk14Y_rsy3ZA39tViU');
      let headers = new Headers({
        "Accept": "application/json"
      });
      // let options = new RequestOptions({ headers });
      that.http.post("https://api-cn.faceplusplus.com/cardpp/v1/ocridcard", formData)
        .subscribe(
          function (result) {
            that.shenfen=result;
            console.log();
          },
          function (error) {
            console.log(error.message);
          }
        )
    }
  }

  toUploadImg(){
    let that = this;
    that.navCtrl.push(OwnerUploadImgPage,{"houseId":that.houseId});

  }

}
